package com.buer.train.api;

import com.buer.train.business.domain.DeptDO;
import com.buer.train.business.service.DeptService;
import com.buer.train.common.annotation.Auth;
import com.buer.train.common.eumn.ResultEnum;
import com.buer.train.common.holder.LoginUser;
import com.buer.train.common.holder.LoginUserHolder;
import com.buer.train.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/school")
@Api(tags = {"学校相关接口"})
public class SchoolController {

    @Autowired
    private DeptService deptService;

    @RequestMapping(value = "/school/getAllSchool", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ApiOperation("获取所有学校")
    @Auth
    public BaseResult getAllSchool(@RequestBody Map<String, Object> params) {
        LoginUser loginUserHolder = LoginUserHolder.getLoginUserHolder();
        params.put("depts",loginUserHolder.getNodeDepts());

        List<DeptDO> deptDOList = deptService.list(params);
        return BaseResult.build(ResultEnum.SUCCESS,deptDOList);
    }
}
